$(function () {

  // 进入个人中心就获取数据进行渲染
  $.ajax({
    url: window.BigNew.user_detail,
    success: function (response) {
      if (response.code == 200) {
        $("#inputEmail1").val(response.data.username);
        $("#inputEmail2").val(response.data.nickname);
        $("#inputEmail3").val(response.data.email);
        $("#inputEmail4").val(response.data.password);
        $('.user_pic').attr('src', response.data.userPic);
      }
    }
  });

  // 改变头像时，把图片进行渲染
  $('#exampleInputFile').on('change', function () {
    let myfile = $(this)[0].files[0];
    let url = URL.createObjectURL(myfile);
    $('.user_pic').attr('src', url);
  });


  // 保存修改的资料，进行请求;
  $(".btn-success").on('click', function () {
    let data = new FormData($('#form')[0]);
    console.log(data);
    $.ajax({
      type: "post",
      url: window.BigNew.user_edit,
      data,
      dataType: 'json',
      contentType: false,
      processData: false,
      success: function (response) {
        if (response.code == 200) {
          alert('修改成功！');
          window.parent.location.reload();
        }
      }
    });
  });
})